package com.example.springbootdemo.task;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

/**
 * TODO
 *
 * @author ：f4cklangzi@gmail.com
 * @date ：Created At 2025/6/30
 */
@Slf4j
@Component
public class Livp {
    
    private static final String PATH = "/nas/home/f4cklangzi/资料/重要文件/来自：iPhone/";
    
    @Scheduled(fixedDelay = 60 * 1000)
    public void run() {
        List<File> files = FileUtil.loopFiles(PATH, file -> file.getName().endsWith("livp"));
        for (File file : files) {
            String fileName = file.getName();
            String name = StrUtil.subBefore(fileName, ".", true);
            String filePath = PATH + fileName;
            String dirPath = PATH + name;
            if (FileUtil.isDirectory(dirPath)) {
                continue;
            }
            Process process = RuntimeUtil.exec("unzip", filePath, "-d", dirPath);
            String exec = RuntimeUtil.getResult(process);
            if (exec.contains("mov")) {
                log.info("[{}]解压成功.", fileName);
            } else {
                log.error("[{}]解压失败:{}", fileName, exec);
            }
            
        }
        
        
    }
}
